package com.dmwork.service.base.config;

import com.google.common.base.Predicates;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket frontApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("frontApi")
                .apiInfo(frontApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/front/.*")))
                .build();
    }

    @Bean
    public Docket adminApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(adminApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    @Bean
    public Docket ossApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("ossApi")
                .apiInfo(ossApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/.*/oss/.*")))
                .build();
    }

    @Bean
    public Docket vodApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("vodApi")
                .apiInfo(vodApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/.*/vod/.*")))
                .build();
    }


    /**
     * vod微服务接口
     * @return
     */
    private ApiInfo vodApiInfo() {
        return new ApiInfoBuilder()
                .title("vod微服务系统-api文档")
                .description("本文档描述了vod微服务微服务接口定义")
                .version("1.0")
                .contact(new Contact("李天", "https://gitee.com/laslas", "330827764@qq.com"))
                .build();
    }

    /**
     * oss微服务接口
     * @return
     */
    private ApiInfo ossApiInfo() {
        return new ApiInfoBuilder()
                .title("oss微服务系统-api文档")
                .description("本文档描述了oss微服务微服务接口定义")
                .version("1.0")
                .contact(new Contact("李天", "https://gitee.com/laslas", "330827764@qq.com"))
                .build();
    }

    /**
     * 前台微服务接口
     * @return
     */
    private ApiInfo frontApiInfo() {
        return new ApiInfoBuilder()
                .title("前台系统-api文档")
                .description("本文档描述了前台系统微服务接口定义")
                .version("1.0")
                .contact(new Contact("李天", "https://gitee.com/laslas", "330827764@qq.com"))
                .build();
    }

    /**
     * 后台管理系统微服务接口
     * @return
     */
    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("后台管理系统-api文档")
                .description("本文档描述了后台管理系统微服务接口定义")
                .version("1.0")
                .contact(new Contact("李天", "https://gitee.com/laslas", "330827764@qq.com"))
                .build();
    }

}
